/**
  ETFDAQ Project
  \class TADAQThread
  \brief the working thread for the DAQ
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2024-08-20
  \date 2024-08-20 last modified

  \copyright Copyright (c) 2024 IMP-CAS with LGPLv3 LICENSE
*/

#ifndef TADAQThread_h
#define TADAQThread_h

#include <QThread>
#include <QMutex>
#include "daqstatus.h"

class QEventLoop;
class TAGDAQ;
class TADAQ;

class TADAQThread : public QThread{
  Q_OBJECT
public:
  TADAQThread(TAGDAQ *gdaq, TADAQ *daq);
  virtual ~TADAQThread();

  EDAQSTA daqStatus();
  TADAQ *DAQ() const{ return fDAQ; }
  virtual void updateDAQInfo();
  virtual void ProcessOneEvent();

public slots:
  virtual void run() override;
  virtual void updateStatus(const EDAQSTA &sta);

protected:
  QMutex fMutex;
  QEventLoop *fEventLoop;
  TAGDAQ *fGDAQ;
  EDAQSTA fDaqSta;
  TADAQ *fDAQ;
  QString fDAQInfo;

  unsigned fEvIdx; ///< for calculating DAQ rate
};

#endif
